home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-09 | 75.2 KB | 2,566 lines | [TEXT/CWIE] |
- // A pict file window
- //
- // David Hayward and Nick Thompson
- // Developer Technical Support
- // AppleLink: DEVSUPPORT
- //
- // Copyrite 1995, Apple Computer,Inc
- //
- // This file contains the handlers procs for a pict file window.
- //
- // 9/13/94 nick first cut
- // 12/13/94 david several modifications
- // 9/25/97 ebb mods to display times and pixel counts
-
-
- #include <PictUtils.h>
- #include <TextUtils.h>
- #include <Types.h>
- #include <Fonts.h>
- #include <Files.h>
- #include <QDOffScreen.h>
- #include <Resources.h>
- #include <StandardFile.h>
- #include <Scrap.h>
- #include <Drag.h>
- #include <GXTypes.h>
-
- #include "appGlobals.h"
- #include "appMain.h"
- #include "appMenus.h"
- #include "appErrors.h"
- #include "appPrint.h"
- #include "appAEvts.h"
-
- #include "win.h"
- #include "winTables.h"
- #include "winPictDoc.h"
- #include "winPictDocGetSet.h"
- #include "winProfile.h"
- #include "winProfileGetSet.h"
- #include "winProfID.h"
- #include "winProfIDGetSet.h"
- #include "winProfList.h"
- #include "winProfListGetSet.h"
-
- #include "dragUtils.h"
- #include "stringUtils.h"
- #include "faux3DUtils.h"
- #include "qdUtils.h"
- #include "resourceUtils.h"
- #include "cursorUtils.h"
- #include "colorsyncUtils.h"
- #include "listsUtils.h"
-
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE DEFINES
- |**| ==============================================================================
- \**/
- #define rPictDocWindID 3000 // 'WIND' resource id
- #define rPictSrceProfRectID 3001
- #define rPictDestProfRectID 3002
- #define rPictPrevProfRectID 3003
- #define rPictEmbdProfRectID 3004
- #define kScrollDelta 16
- #define kWindowWidthMin 500
- #define kWindowHeightMin 200
- #define kHeaderHeight 120
- #define kStatusWidth 300
- #define kCellHeight 16
- #define kMargin 16
- #define kCSyncACursor 150
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE GLOBALS
- |**| ==============================================================================
- \**/
- static RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
- static RGBColor ltGray = {0xDDDD, 0xDDDD, 0xDDDD};
- static RGBColor mdGray = {0x7FFF, 0x7FFF, 0x7FFF};
- static RGBColor dkGray = {0x3FFF, 0x3FFF, 0x3FFF};
- static Boolean acceptableDragFlag;
- static Boolean windowIsHilightedFlag;
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTION PROTOTYPES
- |**| ==============================================================================
- \**/
- void DoDrawPictData ( winHandle win, GrafPtr destPort, Rect *srcRect, Rect *dstRect ) ;
- OSErr DoCreatePalettes ( winHandle win ) ;
- ListHandle BuildProfList ( winHandle win ) ;
- OSErr DoCreatePictWindow ( winHandle win ) ;
- OSErr DoCreateDragZones ( winHandle win ) ;
- pascal void PictDocActionProc ( ControlHandle cntl, short part) ;
- void UpdatePane ( winHandle win, Rect updateRect ) ;
- void ScrollPane ( winHandle win, ControlHandle cntl, short oldCntlVal ) ;
- void UpdatePict ( winHandle win, short which ) ;
- void ChangeCSOnOff ( winHandle win ) ;
- void ChangeCSMode ( winHandle win ) ;
- Boolean SetWinContentColor ( WindowRef window, RGBColor theColor ) ;
- OSErr GetProfileFromFront ( CMProfileRef *prof ) ;
- OSErr GetProfIDFromFront ( CMProfileIdentifierHdl *IDHdl ) ;
- void DoChangeProfile ( winHandle win, short which, CMProfileRef prof ) ;
- void DoChangeProfileFromFront ( winHandle win, short which ) ;
- OSErr DoAddEmbdProf ( winHandle win, CMProfileRef prof, unsigned long flags ) ;
- OSErr DoAddEmbdProfID ( winHandle win, CMProfileIdentifierHdl IDHdl ) ;
- void DoAddEmbdProfFromFront ( winHandle win, unsigned long flags ) ;
- void SaveCmndPictDoc ( winHandle win ) ;
- void SaveAsCmndPictDoc ( winHandle win ) ;
- void RevertCmndPictDoc ( winHandle win ) ;
- void CopyCmndPictDoc ( winHandle win ) ;
- void PasteCmndPictDoc ( winHandle win ) ;
- void DoChangePict ( winHandle win, Handle hand, OSType type ) ;
-
- short DoDragPict ( winHandle win, EventRecord *e, Rect hiliteRect ) ;
- pascal OSErr MyDragSendDataProc ( FlavorType theDragFlavor, void *refCon, ItemReference theItem, DragReference theDrag ) ;
- pascal OSErr MyDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow, Point theLocation, Handle dataHdl ) ;
- pascal OSErr MyProfDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow, Point theLocation, Handle dataHdl ) ;
-
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- winActivatePictDoc
- *------------------------------------------------------------------------------*
- This is a ActivateProcPtr for PictDoc windows.
- Things, such as activating/deactivation controls should go here
- This ProcPtr is envoked by CallWinActivateProc() which is called by:
- DoActivateEvent() which dispaches activate events and
- DoOSEvent() which handles events such as Suspend/Resume.
- \*------------------------------------------------------------------------------*/
- void winActivatePictDoc ( winHandle win, Boolean activating )
- {
- Rect growRect ;
-
- if (activating)
- {
- ShowControl( GetPictDocCntl(win,rPictDocHorzScrollID) ) ;
- ShowControl( GetPictDocCntl(win,rPictDocVertScrollID) ) ;
- }
- else
- {
- HideControl( GetPictDocCntl(win,rPictDocHorzScrollID) ) ;
- HideControl( GetPictDocCntl(win,rPictDocVertScrollID) ) ;
- }
- growRect = GetWinRect( win ) ; // check if ok?
- growRect.top = growRect.bottom - kScrollDelta ;
- growRect.left = growRect.right - kScrollDelta ;
- InvalRect( &growRect ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winUpdatePictDoc
- *------------------------------------------------------------------------------*
- This is a UpdateProcPtr for PictDoc windows.
- It handles all drawing into the window.
- For PictDoc windows, this means that this routine is responible for
- drawing the scroll bars, grow box, the header area, and the Pict itself.
- The Pict is drawn in the space provided by the current window size and
- in accordance with the scroll bar values. It is drawn by calling
- DoDrawPictData() which is also used by the PagePrintProc.
- This ProcPtr is envoked by CallWinUpdateProc() which is called by:
- DoUpdateEvent() which dispaches update events.
- \*------------------------------------------------------------------------------*/
- void winUpdatePictDoc ( winHandle win, EventRecord *e )
- {
- Rect docRect ;
- Rect pictRect ;
- Rect headRect, headUpdateRect ;
- Rect growRect, growUpdateRect ;
- Rect statRect, statUpdateRect ;
- WindowRef window = (WindowRef)e->message;
- Rect updateRect = ((**(((CGrafPtr)window)->visRgn)).rgnBBox) ;
- GrafPtr savedPort ;
-
- GetPort( &savedPort ) ;
- SetPort( (GrafPtr)window ) ;
-
- BeginUpdate( window ) ;
-
- docRect = GetWinRect( win ) ; // check if ok?
- pictRect = GetPictDocPictRect( win ) ; // check if ok?
-
- // draw header
- headRect = docRect ;
- headRect.bottom = kHeaderHeight;
- headRect.bottom -= 3;
- if (SectRect(&headRect,&updateRect,&headUpdateRect))
- {
- faux3DFillRect ( &headRect ) ;
- ForeColor(whiteColor) ;
- MoveTo (headRect.left, headRect.bottom+1) ; LineTo (headRect.right, headRect.bottom+1) ;
- ForeColor(blackColor) ;
- MoveTo (headRect.left, headRect.bottom ) ; LineTo (headRect.right, headRect.bottom ) ;
- MoveTo (headRect.left, headRect.bottom+2) ; LineTo (headRect.right, headRect.bottom+2) ;
- {
- Rect embdRect, srceRect, destRect, prevRect ;
- Str255 embdProfStr, srceProfStr, destProfStr, prevProfStr ;
- CMError cmerr ;
- ListHandle list ;
-
- // get rects from resources
- srceRect = GetRect( rPictSrceProfRectID ) ;
- destRect = GetRect( rPictDestProfRectID ) ;
- prevRect = GetRect( rPictPrevProfRectID ) ;
- embdRect = GetRect( rPictEmbdProfRectID ) ;
-
- TextSize(9) ;
- TextFace(bold) ;
- TextFont(applFont) ;
- ForeColor(blackColor) ;
-
- GetStringPtr ( rPictSrceProfRectID, srceProfStr ) ;
- GetStringPtr ( rPictDestProfRectID, destProfStr ) ;
- GetStringPtr ( rPictPrevProfRectID, prevProfStr ) ;
- GetStringPtr ( rPictEmbdProfRectID, embdProfStr ) ;
-
- MoveTo( srceRect.left +4, srceRect.top -4) ; DrawString( srceProfStr ) ;
- MoveTo( destRect.left +4, destRect.top -4) ; DrawString( destProfStr ) ;
- MoveTo( prevRect.left +4, prevRect.top -4) ; DrawString( prevProfStr ) ;
- MoveTo( embdRect.left +4, embdRect.top -4) ; DrawString( embdProfStr ) ;
-
- faux3DFillRectIn( &srceRect ) ;
- faux3DFillRectIn( &destRect ) ;
- faux3DFillRectIn( &prevRect ) ;
- faux3DFillRectIn( &embdRect ) ;
-
- TextSize(9) ;
- TextFace(0) ;
- TextFont(applFont) ;
- ForeColor(blackColor) ;
-
- cmerr = GetProfName ( GetPictDocProfile( win, kSrceProf ), srceProfStr ) ;
- cmerr = GetProfName ( GetPictDocProfile( win, kDestProf ), destProfStr ) ;
- cmerr = GetProfName ( GetPictDocProfile( win, kPrevProf ), prevProfStr ) ;
-
- list = GetPictDocProfList( win ) ;
- if (list != nil )
- {
- LSetDrawingMode( true, list ) ;
- LUpdate( ((CGrafPtr)window)->visRgn, list) ; // not sure this is the rgn
- }
-
- TruncString( srceRect.right - srceRect.left - 6 , srceProfStr, smTruncEnd ) ;
- TruncString( destRect.right - destRect.left - 6 , destProfStr, smTruncEnd ) ;
- TruncString( prevRect.right - prevRect.left - 6 , prevProfStr, smTruncEnd ) ;
-
- MoveTo (srceRect.left +6, srceRect.top + 14) ; DrawString( srceProfStr ) ;
- MoveTo (destRect.left +6, destRect.top + 14) ; DrawString( destProfStr ) ;
- MoveTo (prevRect.left +6, prevRect.top + 14) ; DrawString( prevProfStr ) ;
- }
- }
-
- // update controls
- TextSize(9) ;
- TextFace(bold) ;
- TextFont(applFont) ;
- SetWinContentColor ( window, ltGray ) ;
- DrawControls( window ) ;
- SetWinContentColor ( window, white ) ; // should restore previous
- {
- short val;
- val = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
- SetPictDocCntlValue( win, rPictDocMatchOnOffID, !val ) ;
- SetPictDocCntlValue( win, rPictDocMatchOnOffID, val ) ;
- }
-
- // draw GrowIcon
- growRect = docRect ;
- growRect.top += kHeaderHeight ;
- if (SectRect(&growRect,&updateRect,&growUpdateRect))
- {
- RgnHandle saveRgn = NewRgn() ;
- GetClip( saveRgn ) ;
- ClipRect( &growRect ) ;
- DrawGrowIcon( window ) ;
- SetClip( saveRgn ) ;
- DisposeRgn( saveRgn ) ;
- }
-
- // startdraw status box
- statRect = docRect ;
- statRect.top = statRect.bottom +1 - kScrollWidth ;
- statRect.right = kStatusWidth - 1 ;
- if (SectRect(&statRect,&updateRect,&statUpdateRect))
- {
- faux3DFillRect ( &statRect ) ;
- InsetRect( &statRect, -1, -1 ) ;
- ForeColor(blackColor) ;
- FrameRect( &statRect ) ;
- }
-
- // draw scrolling pane
- UpdatePane( win, updateRect ) ;
-
- // finish drawing status box
- if (SectRect(&statRect,&updateRect,&statUpdateRect))
- {
- Str255 string ;
- OSType subtype;
- Fixed fix ;
- Point penPt ;
- short mode, cson ;
- #define kTextOffset 16 // pixels between strings
-
- subtype = GetWinSubtype ( win ) ;
-
- ForeColor(blackColor) ;
- TextSize(9) ;
- TextFace(0) ;
- TextFont(applFont) ;
-
- cson = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
- mode = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
- if (!cson) mode = kOriginal ;
-
- // Move the pen to the starting position
- MoveTo( statRect.left, statRect.bottom-4 ) ;
-
- if ( mode != kDrwMchdPct )
- {
- long bytes ;
- bytes = GetHandleSize( (Handle)GetPictDocPict(win,mode) ) ;
- fix = (Fixed)(bytes<<6) ;
- FormatFixed( fix, rKBytesFMAT, string) ;
-
- // Used to be MoveTo( statRect.left+10, statRect.bottom-4 ) ;
- // Advance the pen horizontally, and draw
- GetPen( &penPt );
- MoveTo ( penPt.h + kTextOffset, penPt.v );
- DrawString( string ) ;
- }
-
- if ( mode != kOriginal )
- {
- unsigned long ticks ;
- unsigned long pixels;
- Fixed secs ;
- short formatID;
-
- // Do the total first
- ticks = GetPictDocDrawTime(win,mode+kTotal) ;
- secs = FixRatio( (short)ticks, 60 ) ;
- FormatFixed( secs, rSecsFMAT, string) ;
-
- // Used to be MoveTo( statRect.left+50, statRect.bottom-4 ) ;
- // Advance the pen, and draw
- GetPen( &penPt );
- MoveTo ( penPt.h + kTextOffset, penPt.v );
- DrawString( string ) ;
-
- // Do the actual matching or checking or proofing time next, in bold
- ticks = GetPictDocDrawTime(win,mode) ;
- secs = FixRatio( (short)ticks, 60 ) ;
- FormatFixed( secs, rSecsFMAT, string) ;
- TextFace( bold ) ;
-
- // Advance the pen, and draw
- GetPen( &penPt );
- MoveTo ( penPt.h + kTextOffset, penPt.v );
- DrawString( string ) ;
-
- // Restore face to plain
- TextFace(0) ;
-
- // Do the pixel count, in MPixels/sec - which we need "ticks" for
- pixels = GetPictDocDrawCount(win);
- ticks = GetPictDocDrawTime(win,mode) ;
- if (pixels != 0 && ticks != 0)
- {
- // first get seconds
- secs = FixRatio( (short)ticks, 60 ) ;
-
- // now get MPixels = pixels / 1024 * 1024
- // or KPixels
- if (pixels > 1048576)
- {
- formatID = rMPixPerSecFMAT ;
- pixels = pixels / 1048576 ;
- }
- else
- {
- formatID = rKPixPerSecFMAT ;
- pixels = pixels / 1024 ;
- }
-
- fix = FixDiv(Long2Fix(pixels), secs) ;
- FormatFixed( fix, formatID, string) ;
-
- // Finally we have a string
- // Advance the pen, and draw
- GetPen( &penPt );
- MoveTo ( penPt.h + kTextOffset, penPt.v );
- DrawString( string ) ;
- }
- }
- }
-
- // signal that we finished drawing
- EndUpdate( window ) ;
- SetPort( savedPort ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winClickPictDoc
- *------------------------------------------------------------------------------*
- This is a ClickProcPtr for PictDoc windows.
- So far, all this contains is a crude handling of the scroll controls
- Other things, such as initiating a drag-and-drop should also go here
- This ProcPtr is envoked by CallWinClickProc() which is called by:
- DoMouseDownEvent() which dispaches mouse down events
- \*------------------------------------------------------------------------------*/
- void winClickPictDoc ( winHandle win, EventRecord *e )
- {
- Point pt = e->where;
- ControlHandle hCtl, vCtl, csonCtl, modeCtl ;
- WindowRef window ;
- Boolean dblClk = false ;
- Point cell = {0,0} ;
- ListHandle list ;
- unsigned long index ;
- ControlHandle cntl ;
- short oldCntlVal ;
- short cntlPart ;
- ControlActionUPP caUPP ;
- Boolean notAtEnd = true ;
-
- window = GetWinWindow( win ) ;
- SetPort ( (GrafPtr)window ) ;
- GlobalToLocal( &pt ) ;
-
- hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
- vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
- csonCtl = GetPictDocCntl( win, rPictDocMatchOnOffID ) ;
- modeCtl = GetPictDocCntl( win, rPictDocMatchPopupID ) ;
-
- list = GetPictDocProfList( win ) ;
- if ( list )
- dblClk = LClick( pt, e->modifiers, list ) ;
-
- if ( dblClk )
- {
- while ( notAtEnd && LGetSelect(true, &cell, list))
- {
- OSErr err = noErr ;
- CMError cmerr = noErr ;
- CMProfileRef prof ;
- CMProfileRef profCopy ;
- winHandle profWin ;
- FSSpec spec ;
-
- index = cell.v +1 ;
-
- cmerr = GetIndexedProfileFromPicHandle( GetPictDocPict(win,kOriginal), index, &prof, nil ) ;
- cmerr = ReOpenProfileRef ( &profCopy, prof ) ;
- CMCloseProfile( prof ) ;
-
- // create a new winHandle of the proper type
- if ( IsPseudoProfile(prof) )
- {
- CMProfileIdentifierHdl profID;
- err = NewWinHandle( &profWin, winAllocProfID ) ;
- WarnIfErr( err ) ;
- if (err) return ;
-
- err = GetPseudoProfileIDHdl( prof, &profID ) ;
- SetProfIDIDHdl( profWin, profID ) ;
- SetProfIDIndex( profWin, index ) ;
- }
- else
- {
- err = NewWinHandle( &profWin, winAllocProfile ) ;
- WarnIfErr( err ) ;
- if (err) return ;
-
- SetProfileRef( profWin, profCopy ) ;
- SetProfileIndex( profWin, index ) ;
- }
- spec = GetWinFSSpec(win) ;
- SetWinFSSpec( profWin, &spec ) ;
- SetWinSubtype( profWin, kEmbededSubType ) ;
- err = CallWinOpenProc ( profWin ) ;
-
- if ( err != noErr ) // if an error occured
- DisposeWinHandle( profWin ) ;
- if ( err == kWasAlreadyOpen )
- err = noErr;
-
- notAtEnd = LNextCell( false, true, &cell, list ) ;
- }
- }
-
- cntlPart = FindControl(pt, window, &cntl) ;
-
- if ( cntl==hCtl || cntl==vCtl )
- {
- switch (cntlPart)
- {
- case kControlUpButtonPart :
- case kControlDownButtonPart :
- case kControlPageUpPart :
- case kControlPageDownPart :
- caUPP = NewControlActionProc(PictDocActionProc) ;
- cntlPart = TrackControl( cntl, pt, (ControlActionUPP)caUPP ) ;
- DisposeRoutineDescriptor( caUPP ) ;
- break;
- case kControlIndicatorPart :
- oldCntlVal = GetControlValue( cntl ) ;
- cntlPart = TrackControl( cntl, pt ,nil) ;
- if ( cntlPart != 0 )
- ScrollPane( win, cntl, oldCntlVal ) ;
- break;
- }
- }
- if ( cntl==csonCtl )
- {
- TextSize(9) ;
- TextFace(bold) ;
- TextFont(applFont) ;
- cntlPart = TrackControl( cntl, pt ,nil) ;
- if ( cntlPart != 0 )
- ChangeCSOnOff( win ) ;
- }
- if ( cntl==modeCtl )
- {
- TextSize(9) ;
- TextFace(bold) ;
- TextFont(applFont) ;
- cntlPart = TrackControl( cntl, pt ,(ControlActionUPP)-1) ;
- if ( cntlPart != 0 )
- ChangeCSMode( win ) ;
- }
-
- // handle drag of pict
- {
- Rect paneRect = GetPictDocPaneRect( win ) ;
- Rect pictRect = GetPictDocPictRect( win ) ;
- Rect dragRect ;
- short HorzDelta, VertDelta ;
-
- HorzDelta = GetPictDocCntlValue(win,rPictDocHorzScrollID) * kScrollDelta
- + pictRect.left
- - kMargin
- - paneRect.left ;
-
- VertDelta = GetPictDocCntlValue(win,rPictDocVertScrollID) * kScrollDelta
- + pictRect.top
- - kMargin
- - paneRect.top ;
-
- dragRect = pictRect ;
- OffsetRect( &dragRect, -HorzDelta, -VertDelta ) ;
- SectRect(&dragRect,&paneRect,&dragRect) ;
-
- if ( PtInRect(pt,&dragRect) )
- DoDragPict( win, e, dragRect) ;
- }
-
- }
-
-
- /*------------------------------------------------------------------------------*\
- winResizePictDoc
- *------------------------------------------------------------------------------*
- This is a ResizeProcPtr for PictDoc windows.
- This routine is responsible for re-arranging the contents of the window if
- it is resized. On entry to this routine, the new window size can be found
- in the document's window's portRect. At the very least, this routine
- should call SetWinRect() to put the new window size in the winHandle.
- So far, the only other thing this routine does is repostion the scroll controls
- and issue the appropriate update events so everything is re-drawn correctly.
- This ProcPtr is envoked by CallWinResizeProc() which is called by:
- DoMouseDownEvent() which dispaches mouse down events and
- DoCreatePictWindow() which initially creates the window.
- \*------------------------------------------------------------------------------*/
- void winResizePictDoc ( winHandle win )
- {
- ControlHandle hCtl, vCtl ;
- WindowRef window ;
- Rect horzInval, vertInval ;
- Rect oldDocRect, newDocRect, pictRect ;
- Rect paneRect ;
-
- oldDocRect = GetWinRect( win ) ;
- pictRect = GetPictDocPictRect( win ) ;
-
- window = GetWinWindow ( win ) ;
- newDocRect = ((CGrafPtr)window)->portRect ;
- SetWinRect( win, newDocRect ) ;
-
- horzInval = vertInval = newDocRect ;
- horzInval.top = MIN( oldDocRect.bottom, newDocRect.bottom) - kScrollWidth;
- vertInval.left = MIN( oldDocRect.right, newDocRect.right) - kScrollWidth;
- InvalRect( &horzInval ) ;
- InvalRect( &vertInval ) ;
- EraseRect( &horzInval ) ;
- EraseRect( &vertInval ) ;
-
- hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
- vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
-
- paneRect = newDocRect ;
- paneRect.top += kHeaderHeight ;
- paneRect.bottom -= kScrollWidth ;
- paneRect.right -= kScrollWidth ;
- SetPictDocPaneRect( win, paneRect ) ;
-
- MoveControl(hCtl, (paneRect.left-1)+kStatusWidth,
- paneRect.bottom ) ;
- MoveControl(vCtl, paneRect.right,
- paneRect.top-1) ;
-
- SizeControl(hCtl, (2+paneRect.right-paneRect.left)-kStatusWidth,
- kScrollWidth+1) ;
- SizeControl(vCtl, kScrollWidth+1,
- 2+paneRect.bottom-paneRect.top) ;
-
- { // position vertical control
- short pV, wV, max, oldCntlVal ;
-
- pV = pictRect.bottom - pictRect.top ;
- pV += kMargin + kMargin ;
- wV = paneRect.bottom - paneRect.top ;
- if (wV>=pV)
- max = 0 ;
- else
- max = ((MAX (0, pV-wV )) / kScrollDelta) +1 ;
- oldCntlVal = GetControlValue(vCtl) ;
- SetControlMinimum(vCtl, 0) ;
- SetControlMaximum(vCtl, max) ;
- SetControlValue (vCtl, oldCntlVal ) ;
-
- HiliteControl(vCtl, (max==0)?(255):(0) ) ;
- ScrollPane( win, vCtl, oldCntlVal ) ;
- }
-
- { // position hoizontal control
- short pH, wH, max, oldCntlVal ;
-
- pH = pictRect.right - pictRect.left ;
- pH += kMargin + kMargin ;
- wH = paneRect.right - paneRect.left ;
- if (wH>=pH)
- max = 0 ;
- else
- max = ((MAX (0, pH-wH )) / kScrollDelta) +1 ;
- oldCntlVal = GetControlValue(hCtl) ;
- SetControlMinimum(hCtl, 0) ;
- SetControlMaximum(hCtl, max) ;
- SetControlValue (hCtl, oldCntlVal ) ;
-
- HiliteControl(hCtl, (max==0)?(255):(0) ) ;
- ScrollPane( win, hCtl, oldCntlVal ) ;
- }
-
- { // position drag&drop zone
- DragZonesHdl zones ;
- DragZoneHdl zone ;
-
- zones = GetPictDocDragZones( win ) ;
- if ( zones )
- {
- if ( FindDragZones( zones, 'PICT', 0L, 0, 1, &zone ) == 1 )
- (**zone).rect = paneRect ;
- if ( FindDragZones( zones, flavorTypeHFS,'PICT', 0, 1, &zone ) == 1 )
- (**zone).rect = paneRect ;
- }
- }
-
- return ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winClosePictDoc
- *------------------------------------------------------------------------------*
- This is a CloseProcPtr for PictDoc windows.
- So far, all this does is call DisposeWinHandle()
- Other things, such as prompting the user to save the file, could go here.
- This ProcPtr is envoked by CallWinCloseProc() which is called by:
- app_aePDOC_handler() which handles PDOC AppleEvents,
- DoMouseDownEvent() which dispached click events (e.g. close box), and
- MenuProcPtrs which are called whenever menu events occur.
- \*------------------------------------------------------------------------------*/
- void winClosePictDoc ( winHandle win )
- {
- // could do something like ask the user to save if dirty
-
- // if "Save"
- // SaveCmndPictDoc( win ) ;
- // DisposeWinHandle( win ) ;
-
- // if "Cancel"
- // do nothing ?
-
- // if "Don't save"
- // DisposeWinHandle( win ) ;
-
- DisposeWinHandle( win ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winMenuPictDoc
- *------------------------------------------------------------------------------*
- This is a MenuProcPtr for PictDoc windows.
- This routine dispatches any menu commands that the window can handle
- to the appropriate function.
- This ProcPtr is envoked by CallWinMenuProc() which is called by:
- HandleMenuCommand() which dispatches all menu events.
- \*------------------------------------------------------------------------------*/
- void winMenuPictDoc ( winHandle win, long menuResult, Boolean *didit )
- {
- short menuID;
- short menuItem;
-
- *didit = true ;
- menuID = HiWrd(menuResult) ;
- menuItem = LoWrd(menuResult) ;
- switch ( menuID )
- {
- case mFile:
- switch ( menuItem )
- {
- case iSave: // save this document under the name it was opened
- SaveCmndPictDoc( win ) ;
- break ;
- case iSaveAs: // save this document under a new name
- SaveAsCmndPictDoc( win ) ;
- break ;
- case iRevert: // discard all changes made to the document since it was last saved
- RevertCmndPictDoc( win ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- case mEdit:
- switch ( menuItem )
- {
- case iPaste: // discard all changes made to the document since it was last saved
- PasteCmndPictDoc( win ) ;
- break ;
- case iCopy:
- CopyCmndPictDoc( win ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- case mProfiles:
- switch ( menuItem )
- {
- case iMakeSrceProf:
- DoChangeProfileFromFront( win, kSrceProf ) ;
- break ;
- case iMakeDestProf:
- DoChangeProfileFromFront( win, kDestProf ) ;
- break ;
- case iMakePrevProf:
- DoChangeProfileFromFront( win, kPrevProf ) ;
- break ;
- case iMakeEmbdProf:
- DoAddEmbdProfFromFront( win, cmEmbedWholeProfile ) ;
- break ;
- case iMakeEmbdProfID:
- DoAddEmbdProfFromFront( win, cmEmbedProfileIdentifier ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- default :
- *didit = false ;
- break ;
- }
- HiliteMenu(0) ; // Unhighlight whatever MenuSelect or MenuKey hilited
- }
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateMenusPictDoc
- *------------------------------------------------------------------------------*
- This is a UpdateMenusProcPtr for the PictDoc window.
- This routine enables any menu commands that the window can handle.
- For the PictDoc window, the needed items are in the File and Edit menus
- This ProcPtr is envoked by CallWinUpdateMenusProc() which is called by:
- DoAppAdjustMenus() which enables menu commands.
- \*------------------------------------------------------------------------------*/
- void winUpdateMenusPictDoc ( winHandle win )
- {
- MenuHandle theMenu ;
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- Boolean pictOnScrap;
- long scrapOffset ;
- OSType subtype;
- winHandle frontWin;
-
- frontWin = GetFrontWindowWinHandle() ;
-
- if ( win == frontWin )
- {
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- subtype = GetWinSubtype( win ) ;
- pictOnScrap = (GetScrap(nil,'PICT',&scrapOffset) > 0) ;
- hasFile = ( spec.name[0] > 0 ) ;
-
- // do the file menu
- theMenu = GetMenuHandle ( mFile ) ;
-
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iClose ) ;
- if (subtype!=nil)
- {
- EnableItem ( theMenu, iSaveAs ) ;
- #ifdef PIGS_SHELL_PRINT
- EnableItem ( theMenu, iPageSetup ) ;
- EnableItem ( theMenu, iPrint ) ;
- EnableItem ( theMenu, iPrintOne ) ;
- #endif
- }
-
- // for the next 2, check to see if the document has been changed
- if ( dirty )
- EnableItem ( theMenu, iSave ) ;
- if ( dirty && hasFile )
- EnableItem ( theMenu, iRevert ) ;
-
- // do the edit menu
- theMenu = GetMenuHandle ( mEdit ) ;
-
- if ( pictOnScrap )
- {
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iPaste ) ;
- }
-
- if (subtype!=nil)
- {
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iCopy ) ;
- }
- }
- else
- {
- OSType frontType, frontSubtype;
-
- // do the profiles menu
- theMenu = GetMenuHandle ( mProfiles ) ;
-
- frontType = GetWinType( frontWin ) ;
- frontSubtype = GetWinSubtype( frontWin ) ;
-
- if (frontType == kProfileType)
- {
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iMakeSrceProf ) ;
- EnableItem ( theMenu, iMakeDestProf ) ;
- EnableItem ( theMenu, iMakePrevProf ) ;
- if ( frontSubtype!=kSysProfSubType )
- {
- EnableItem ( theMenu, iMakeEmbdProf ) ;
- EnableItem ( theMenu, iMakeEmbdProfID ) ;
- }
- }
- if (frontType == kProfIDType)
- {
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iMakeEmbdProfID ) ;
- }
- if (frontType == kProfListType)
- {
- Cell cell;
- ListHandle list;
-
- list = GetProfListList( frontWin ) ;
- if ( GetSingleSelect( &cell, list)) // if we can fine one selected item
- {
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iMakeSrceProf ) ;
- EnableItem ( theMenu, iMakeDestProf ) ;
- EnableItem ( theMenu, iMakePrevProf ) ;
- EnableItem ( theMenu, iMakeEmbdProf ) ;
- EnableItem ( theMenu, iMakeEmbdProfID ) ;
- }
- }
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- winAllocPictDoc
- *------------------------------------------------------------------------------*
- This is a AllocProcPtr for PictDoc windows.
- This routine is responsible for filling in all the needed fields of the
- winHandle structure. This routine shouldn't be called directly.
- Instead, the code which needs to create a document of this type should
- call NewWinHandle(win,winAllocPictDoc) to envoke this function.
- This ProcPtr is envoked by NewWinHandle() which is called by:
- app_aeODOC_handler() which handles ODOC AppleEvents, and
- app_aePDOC_handler() which handles PDOC AppleEvents.
- \*------------------------------------------------------------------------------*/
- OSErr winAllocPictDoc ( winHandle win )
- {
- OSErr err = noErr ;
- PictDocDataHdl data ;
-
- // set the window type
- SetWinType( win, kPictDocType ) ;
-
- // allocate data handle
- data = (PictDocDataHdl)NewHandleClear( sizeof(PictDocDataRec) ) ;
- if ( data == nil ) return MemError() ;
- SetWinData ( win, (Handle)data ) ;
- (**data).PictMatchedNeedsUpdate =
- (**data).PictProofedNeedsUpdate =
- (**data).PictCheckedNeedsUpdate = true ;
-
- // stuff winHandle fields
- SetWinActivateProc ( win, (ActivateProcPtr) winActivatePictDoc ) ;
- SetWinUpdateProc ( win, (UpdateProcPtr) winUpdatePictDoc ) ;
- SetWinClickProc ( win, (ClickProcPtr) winClickPictDoc ) ;
- SetWinMenuProc ( win, (MenuProcPtr) winMenuPictDoc ) ;
- SetWinUpdateMenusProc ( win, (UpdateMenusProcPtr) winUpdateMenusPictDoc ) ;
- SetWinResizeProc ( win, (ResizeProcPtr) winResizePictDoc ) ;
- SetWinNewProc ( win, (NewProcPtr) winNewPictDoc ) ;
- SetWinOpenProc ( win, (OpenProcPtr) winOpenPictDoc ) ;
- SetWinCloseProc ( win, (CloseProcPtr) winClosePictDoc ) ;
- SetWinDisposeProc ( win, (DisposeProcPtr) winDisposePictDoc ) ;
-
- #ifdef PIGS_SHELL_PRINT
- SetWinPageCountProc ( win, (PageCountProcPtr) winPageCountPictDoc ) ;
- SetWinPagePrintProc ( win, (PagePrintProcPtr) winPagePrintPictDoc ) ;
- #endif
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winNewPictDoc
- *------------------------------------------------------------------------------*
- This is a NewProcPtr for PictDoc windows.
- This routine is responsible for creating and empty a PictDoc window after all the
- needed fields of the winHandle structure have been filled in by winAllocPictDoc.
- This routine shouldn't be called directly. Instead, the code which needs
- to create a document of this type should call NewWinHandle(win,winAllocPictDoc)
- and then CallWinNewProc(win) to envoke this function.
- This ProcPtr is envoked by CallWinNewProc() which is called by:
- DoNewCommand() which creates a new PictDoc window.
- \*------------------------------------------------------------------------------*/
- OSErr winNewPictDoc ( winHandle win )
- {
- OSErr err = noErr ;
-
- err = DoCreatePictWindow( win ) ;
- if ( err ) return err ;
-
- #ifdef PIGS_SHELL_PRINT
- err = DoAppGetPrintStrutures( win ) ;
- if ( err ) err = noErr ; // dont worry, we'll try again if the user prints
- #endif
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winOpenPictDoc
- *------------------------------------------------------------------------------*
- This is a OpenProcPtr for PictDoc windows.
- This routine is responsible for opening a PictDoc window after all the
- needed fields of the winHandle structure have been filled in by winAllocPictDoc.
- On entry the DocumentRecord must contain a valid FSSpec.
- If a PictDoc window for the FSSpec is already onen, then this routine
- will bring it to the front instead of opening a second window.
- This routine shouldn't be called directly. Instead, the code which needs
- to create a document of this type should call NewWinHandle(win,winAllocPictDoc),
- SetWinFSSpec(win,spec), and then CallWinOpenProc(win) to envoke this function.
- This ProcPtr is envoked by CallWinOpenProc() which is called by:
- app_aeODOC_handler() which handles ODOC AppleEvents, and
- app_aePDOC_handler() which handles PDOC AppleEvents.
- \*------------------------------------------------------------------------------*/
- OSErr winOpenPictDoc ( winHandle win )
- {
- OSErr err = noErr ;
- Rect rect ;
- FSSpec spec ;
- OSType subtype;
- winHandle existingDoc ;
-
- spec = GetWinFSSpec( win ) ;
-
- // see if we are already open
- if ( FindWinHandle( &spec, kPictDocType, nil, 1, 1, &existingDoc ) == 1 )
- {
- // bring it to the front
- SelectWindow( GetWinWindow(existingDoc) ) ;
- return kWasAlreadyOpen;
- }
-
- subtype = GetWinSubtype ( win ) ;
-
- if (subtype==kProfDocPictSubtype)
- {
- PicHandle pict ;
-
- // try to read the pict
- err = DoReadPICT ( spec, &pict ) ;
- if ( err ) return err ;
-
- // set the window's pict
- SetPictDocPict( win, kOriginal, pict ) ;
-
- // set the window's rect
- rect = (**pict).picFrame ;
- SetPictDocPictRect( win, rect ) ;
-
- // set the window's update flags
- SetPictDocNeedsUpdate( win, kMatched, true ) ;
- SetPictDocNeedsUpdate( win, kProofed, true ) ;
- SetPictDocNeedsUpdate( win, kChecked, true ) ;
-
- // err = DoCreatePalettes( win ) ;
- // if ( err ) return err ;
- }
-
- err = DoCreatePictWindow( win ) ;
- if ( err ) return err ;
-
- #ifdef PIGS_SHELL_PRINT
- err = DoAppGetPrintStrutures( win ) ;
- if ( err ) err = noErr ; // dont worry, we'll try again if the user prints
- #endif
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winDisposePictDoc
- *------------------------------------------------------------------------------*
- This is a DisposeProcPtr for PictDoc windows.
- This routine is responsible for disposing of any data that was allocated
- by the document and stored in the its data handle.
- This ProcPtr is envoked by CallWinDisposeProc() which is called by:
- DisposeWinHandle() which disposes of the entire winHandle.
- \*------------------------------------------------------------------------------*/
- void winDisposePictDoc ( winHandle win )
- {
- PictDocDataHdl data ;
- PicHandle pict ;
- PaletteHandle palette ;
- WindowRef window ;
- DragZonesHdl zones ;
- ListHandle list ;
- CMProfileRef prof ;
-
- data = (PictDocDataHdl) GetWinData ( win ) ;
- if ( data==nil ) return;
-
- // dispose of all the PicHandles we used
- pict = GetPictDocPict( win, kOriginal ) ;
- if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
-
- pict = GetPictDocPict( win, kProofed ) ;
- if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
-
- pict = GetPictDocPict( win, kMatched ) ;
- if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
-
- pict = GetPictDocPict( win, kChecked ) ;
- if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
-
- // close of all the Profiles we used
- prof = GetPictDocProfile( win, kSrceProf ) ;
- if ( prof != nil ) CMCloseProfile( prof ) ;
-
- prof = GetPictDocProfile( win, kDestProf ) ;
- if ( prof != nil ) CMCloseProfile( prof ) ;
-
- prof = GetPictDocProfile( win, kPrevProf ) ;
- if ( prof != nil ) CMCloseProfile( prof ) ;
-
- // dispose of the ListHandle we used
- list = GetPictDocProfList ( win ) ;
- if ( list != nil ) LDispose(list) ;
-
- // dispose of the PictPalette we used
- palette = GetPictDocPalette( win ) ;
- if ( palette != nil ) DisposePalette( palette ) ;
-
- // dispose of all controls
- window = GetWinWindow( win ) ;
- if ( window != nil ) KillControls( window ) ;
-
- // dispose of drag&drop zoned structure
- zones = GetPictDocDragZones( win ) ;
- if ( zones != nil ) DisposeDragZonesHandle( zones ) ;
-
- // lastly, dispose of the data handle
- DisposeHandle( (Handle)data ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winPageCountPictDoc
- *------------------------------------------------------------------------------*
- This is a PageCountProcPtr for PictDoc windows.
- This routine is responsible for the number of pages needed to render the
- document's data (whatever it may be) gives the bounds of a page.
- This ProcPtr is envoked by CallWinPageCountProc() which is called by:
- DoPrintLoop() which impliments an old-style printing loop, and
- DoGXPrintLoop() which impliments a GX-style printing loop.
- \*------------------------------------------------------------------------------*/
- OSErr winPageCountPictDoc ( winHandle win, short *pageCount )
- {
- Rect pageRect ;
- Rect pictRect ;
- short horizOffset,
- vertOffset,
- pagesWide, // the number of pages wide the image is
- pagesHigh, // the number pages high for this image
- pageWidth, pageHeight, // dimensions of one page
- pictWidth, pictHeight ; // dimensions of the pict
- OSErr err ;
-
- pictRect = GetPictDocPictRect( win ) ;
- err = DoAppGetPageSize( win, &pageRect ) ;
- if ( err ) return err ;
-
- horizOffset = -(pictRect.left) ;
- vertOffset = -(pictRect.top) ;
-
- OffsetRect( &pictRect, horizOffset, vertOffset ) ; // this should make the origin of the rect (0,0)
-
- pageWidth = pageRect.right - pageRect.left ;
- pageHeight = pageRect.bottom - pageRect.top ;
-
- pictWidth = pictRect.right - pictRect.left ;
- pictHeight = pictRect.bottom - pictRect.top ;
-
- pagesWide = 1+ ( (pictWidth-1) / pageWidth ) ; // round up the number of pages to the nearest
- pagesHigh = 1+ ( (pictHeight-1) / pageHeight ) ; // whole page in each direction.
-
- *pageCount = pagesWide*pagesHigh ;
-
- return noErr ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winPagePrintPictDoc
- *------------------------------------------------------------------------------*
- This is a PagePrintProcPtr for PictDoc windows.
- This routine is responsible for the printing a given page of document's
- data into the destination port.
- This ProcPtr is envoked by CallWinPagePrintProc() which is called by:
- DoPrintLoop() which impliments an old-style printing loop, and
- DoGXPrintLoop() which impliments a GX-style printing loop.
- \*------------------------------------------------------------------------------*/
- OSErr winPagePrintPictDoc ( winHandle win, GrafPtr imagingPort, short pageNum )
- {
- Rect pageRect ;
- Rect pictRect ;
- Rect srcRect, dstRect;
- short pagesWide, // the number of pages wide the image is
- pagesHigh, // the number pages high for this image
- horozTile, // used in the loop to denote the H tile to print from the image
- vertTile ; // used in the loop to denote the V tile to print from the image
- short thisPage = 1; // used to find the page they want us to print
- short pictHOff,
- pictVOff,
- pictWidth, // the width of the win's GWorld
- pictHeight ; // the height of the win's GWorld
- short pageWidth, // the width of one page
- pageHeight ; // the height of one page
- OSErr err ;
- GrafPtr savedPort ;
-
- pictRect = GetPictDocPictRect( win ) ;
- err = DoAppGetPageSize( win, &pageRect ) ;
- if ( err ) return err ;
-
- GetPort( &savedPort ) ;
- SetPort( imagingPort ) ; // be sure to do this
-
- pictHOff = -(pictRect.left) ;
- pictVOff = -(pictRect.top) ;
- pictWidth = pictRect.right - pictRect.left ;
- pictHeight = pictRect.bottom - pictRect.top ;
-
- // OffsetRect( &pictRect, pictHOff, pictVOff ) ; // this should make the origin of the rect (0,0)
-
- pageWidth = pageRect.right - pageRect.left ;
- pageHeight = pageRect.bottom - pageRect.top ;
-
- pagesWide = 1+ ( (pictWidth-1) /pageWidth ) ; // round up the number of pages to the nearest
- pagesHigh = 1+ ( (pictHeight-1)/pageHeight ) ; // whole page in each direction.
-
- thisPage = 1;
- for (vertTile=0; vertTile<pagesHigh; vertTile++)
- {
- for (horozTile=0; horozTile<pagesWide; horozTile++)
- {
- if( thisPage == pageNum ) // is this the page we were called to print
- {
- srcRect = pageRect;
-
- OffsetRect( &srcRect,
- pictRect.left - srcRect.left,
- pictRect.top - srcRect.top ) ;
-
- OffsetRect( &srcRect,
- horozTile * pageWidth,
- vertTile * pageHeight ) ;
-
- SectRect( &srcRect, &pictRect, &srcRect) ;
-
- // finess the rect to print, we'll assume the the top left is always correct.
- // this helps with areas of the pict that don't fit entirely on one page
-
- dstRect = srcRect;
-
- OffsetRect( &dstRect,
- pageRect.left - srcRect.left,
- pageRect.top - srcRect.top ) ;
-
- DoDrawPictData( win, imagingPort, &srcRect, &dstRect ) ;
-
- }
- thisPage++ ; // bump the page number
- }
- }
- SetPort( savedPort ) ; // put the old port back
- return noErr ;
- }
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- DoDrawPictData
- *------------------------------------------------------------------------------*
- This routine draws the postion of the documents data bounded by srcRect,
- into the rectangle dstRect of the destPort.
- data into the destination port.
- This routine is called by:
- winUpdatePictDoc() which draws into the scrollable window, and
- winPagePrintPictDoc() which draws into a printing port.
- \*------------------------------------------------------------------------------*/
- static void DoDrawPictData ( winHandle win, GrafPtr destPort, Rect *srcRect, Rect *dstRect )
- {
- Rect rect;
- PictDocDataHdl data ;
- OSType subtype;
-
- data = (PictDocDataHdl) GetWinData ( win ) ;
- if ( data==nil ) return;
-
- rect = GetPictDocPictRect( win ) ;
- if ( ! ( rect.top || rect.bottom || rect.left || rect.right ) )
- return ;
-
- subtype = GetWinSubtype ( win ) ;
-
- MapRect(&rect, srcRect, dstRect) ;
-
- if (subtype==kProfDocPictSubtype)
- {
- PicHandle pict ;
- RgnHandle savedClipRgn;
- short mode,cson;
-
- SetGWorld( (CGrafPtr)destPort, nil ) ; // set the destPort to be the current port
-
- savedClipRgn = NewRgn() ;
- GetClip(savedClipRgn) ;
- ClipRect(dstRect) ;
-
- cson = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
- mode = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
- if (!cson) mode = kOriginal ;
-
- UpdatePict( win, mode ) ;
- if (mode==kDrwMchdPct)
- {
- pict = GetPictDocPict(win,kOriginal) ;
- if (pict != nil)
- NCMDrawMatchedPicture(pict, GetPictDocProfile(win,kPrevProf), &rect) ;
- else
- EraseRect( &rect ) ;
- }
- else
- {
- pict = GetPictDocPict(win,mode) ;
- if (pict != nil)
- DrawPicture( pict, &rect ) ;
- else
- EraseRect( &rect ) ;
- }
-
- SetClip(savedClipRgn) ;
- DisposeRgn(savedClipRgn) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoCreatePalettes
- *------------------------------------------------------------------------------*
- This routine extracts the palette, and colortable from the document's
- PictHandle and stores them in the dPictPalette and dPictCTab fields of
- the PictDocDataHdl.
- This routine is called by:
- winOpenPictDoc() which fills in the winHandle structure
- \*------------------------------------------------------------------------------*/
- static OSErr DoCreatePalettes ( winHandle win )
- {
- OSErr err ;
- PicHandle pict ;
- PictInfo pictInfo ;
- CTabHandle ctab ;
- PaletteHandle pal ;
- PictDocDataHdl data ;
-
- data = (PictDocDataHdl) GetWinData ( win ) ;
- if ( data==nil ) return nilHandleErr ;
-
- pict = GetPictDocPict( win, kOriginal ) ;
-
- // use the picture utilities to get the palette for the window
- err = GetPictInfo( pict, &pictInfo, returnColorTable, 256, systemMethod, 0) ;
-
- ctab = pictInfo.theColorTable ;
- pal = NewPalette( (**ctab).ctSize +1, ctab, pmTolerant, 0x1000 ) ;
-
- // set up the palette for later use
- SetPictDocPalette( win, pal ) ;
-
- return noErr ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- BuildProfList
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static ListHandle BuildProfList ( winHandle win )
- {
- ListHandle theList = nil ;
- unsigned long count ;
- CMError cmerr ;
- PicHandle pict ;
-
- pict = GetPictDocPict( win, kOriginal ) ;
- if (pict==nil) return nil ;
-
- //------------- search for all profiles
- {
- cmerr = CountProfilesInPicHandle ( pict, &count ) ;
- if (cmerr) goto bail ;
- SetPictDocListCount ( win, count ) ;
- }
-
-
- //------------- build a list
- {
- Rect rView, rDataBnds ;
- Point cellSize ;
- WindowRef window ;
-
- rView = GetRect ( rPictEmbdProfRectID ) ;
- rView.right -= kScrollWidth;
- SetPt( &cellSize, rView.right-rView.left, kCellHeight ) ;
- InsetRect( &rView, 1, 1) ;
-
- window = GetWinWindow ( win ) ;
- SetRect( &rDataBnds, 0,0,1,count ) ;
- theList = LNew(&rView,
- &rDataBnds,
- cellSize,
- 0, // proc ID
- window,
- false, // draw now
- true, // hasGrow
- false, // scrollHoriz
- true ) ; // scrollVert
- SetPictDocProfList( win, theList ) ;
- }
-
-
- //------------- add strings to list cells
- {
- Point theCell ;
- unsigned long v ;
- short dataLen ;
- Str255 name ;
- CMProfileRef prof ;
-
- for ( v=0; v<count; v++ )
- {
- cmerr = GetIndexedProfileFromPicHandle ( pict, v+1, &prof, nil ) ;
- cmerr = GetProfName( prof, (StringPtr)name ) ;
- CMCloseProfile( prof ) ;
-
- SetPt(&theCell,0,v) ;
- dataLen = name[0] ;
- LSetCell( &(name[1]), dataLen, theCell, theList ) ;
- }
- }
-
- //-------------
- bail :
- return theList ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoCreatePictWindow
- *------------------------------------------------------------------------------*
- This routine actually creates the WindowRef for a winHandle.
- After creating the window, it:
- reference the window and the DocumentRecord to each other,
- makes the window the current port,
- loads and adds the scroll bar controls,
- resizes the window according to the Pict (if present),
- attaches the winHandle's palette to the window,
- titles it according the the FSSpec (if present), and
- makes it visible .
- This routine is called by:
- winOpenPictDoc() which is called when opening a pict file
- winNewPictDoc() which is called when creating a new pict window
- \*------------------------------------------------------------------------------*/
- static OSErr DoCreatePictWindow ( winHandle win )
- {
-
- Rect pictRect ;
- Rect sizeRect ;
- OSErr err = noErr ;
- WindowRef window ;
- FSSpec spec;
- PictDocDataHdl data ;
- //PaletteHandle palette ;
- short h,v ;
- ListHandle profList ;
-
- data = (PictDocDataHdl) GetWinData ( win ) ;
- if ( data==nil ) return nilHandleErr ;
-
- // create the window
- window = GetNewCWindow(rPictDocWindID, nil, (WindowRef)-1 ) ;
-
- SetWinWindow( win, window ) ; // save a reference to the window in the DocumentRecord
- SetWindowWinHandle( window, win ) ; // save a reference to the DocumentRecord in the window
-
- SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ; // set the window to be the current port
-
- pictRect = GetPictDocPictRect( win ) ;
-
- h = pictRect.right - pictRect.left ;
- v = pictRect.bottom - pictRect.top ;
- h += kScrollWidth + kMargin + kMargin ;
- v += kScrollWidth + kMargin + kMargin + kHeaderHeight ;
- h = MAX(h, kWindowWidthMin) ;
- v = MAX(v, kWindowHeightMin+kHeaderHeight) ;
-
- SizeWindow( window, h, v, false) ; // we'll update everything later
-
- SetRect( &sizeRect, kWindowWidthMin,
- kWindowHeightMin+kHeaderHeight,
- h+1,v+1) ;
- SetWinSizeRect( win, sizeRect ) ;
-
- // try to make list of embeded profiles
- profList = BuildProfList( win ) ;
-
- // set up drag&drop zones
- err = DoCreateDragZones( win ) ;
- if (err) return err ; // we should dispose window before returning
-
- // set up scroll bars
- SetPictDocCntl( win, rPictDocHorzScrollID, GetNewControl(rPictDocHorzScrollID, window ) ) ;
- SetPictDocCntl( win, rPictDocVertScrollID, GetNewControl(rPictDocVertScrollID, window ) ) ;
- SetPictDocCntl( win, rPictDocMatchOnOffID, GetNewControl(rPictDocMatchOnOffID, window ) ) ;
- SetPictDocCntl( win, rPictDocMatchPopupID, GetNewControl(rPictDocMatchPopupID, window ) ) ;
-
- // this will adjust the controls and drag&drop zones
- CallWinResizeProc( win ) ;
-
- // and if we set up the palette earlier assign it to the window
- // palette = GetPictDocPalette( win ) ;
- // if( palette != nil )
- // SetPalette ( window, palette, true ) ;
- // ActivatePalette ( window ) ;
-
- // set the name of this document window
- spec = GetWinFSSpec( win ) ;
- if ( spec.name[0] )
- SetWTitle( window, spec.name ) ;
-
- // make sure it is visible
- ShowWindow( window ) ;
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoCreateDragZones
- *------------------------------------------------------------------------------*
- This routine is called by:
- \*------------------------------------------------------------------------------*/
- static OSErr DoCreateDragZones ( winHandle win )
- {
- OSErr err = noErr ;
- Rect temp = {0,0,500,500} ;
- DragZonesHdl zones ;
- DragZoneRec zone ;
- OSType subtype ;
-
- zones = NewDragZones( GetWinWindow(win) ) ;
- if (!zones) return err;
-
- subtype = GetWinSubtype ( win ) ;
-
- if ( subtype==nil || subtype==kProfDocPictSubtype)
- {
- zone.rect = temp ;
- zone.flavor = 'PICT' ;
- zone.HFSfileType = '????' ;
- zone.dragRecvUPP = NewDragZoneRecvProc( MyDragZoneRecvCallback ) ;
- err = AddDragZone( zones, &zone ) ;
-
- zone.rect = temp ;
- zone.flavor = flavorTypeHFS ;
- zone.HFSfileType = 'PICT' ;
- zone.dragRecvUPP = NewDragZoneRecvProc( MyDragZoneRecvCallback ) ;
- err = AddDragZone( zones, &zone ) ;
- }
-
- SetPictDocDragZones( win, zones ) ;
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- PictDocActionProc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static pascal void PictDocActionProc ( ControlHandle cntl, short cntlPart)
- {
- ControlHandle hCtl, vCtl ;
- WindowRef window ;
- winHandle win ;
- short oldCntlVal ;
-
- // get win from cntl
- window = (**cntl).contrlOwner ;
-
- // get winHandle from window
- win = GetWindowWinHandle( window ) ;
-
- // get controls from winHandle's data
- hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
- vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
-
- if ( cntl==hCtl || cntl==vCtl)
- {
- oldCntlVal = GetControlValue( cntl ) ;
- switch (cntlPart)
- {
- case kControlUpButtonPart :
- if ( oldCntlVal > (**cntl).contrlMin )
- SetControlValue( cntl, oldCntlVal - 1 ) ;
- break;
- case kControlDownButtonPart :
- if ( oldCntlVal < (**cntl).contrlMax )
- SetControlValue( cntl, oldCntlVal + 1 ) ;
- break;
- case kControlPageUpPart :
- SetControlValue( cntl, oldCntlVal - 5 ) ;
- break;
- case kControlPageDownPart :
- SetControlValue( cntl, oldCntlVal + 5 ) ;
- break;
- case kControlIndicatorPart :
- break;
- }
- ScrollPane( win, cntl, oldCntlVal ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- UpdatePane
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void UpdatePane ( winHandle win, Rect updateRect )
- {
- Rect paneRect, paneUpdateRect ;
- Rect pictRect, pictUpdateRect ;
- Rect pictRelPaneRect, pictUpdateRelPaneRect ;
- WindowRef window ;
- OSType subtype;
-
- window = GetWinWindow( win ) ;
- subtype = GetWinSubtype ( win ) ;
-
- if (subtype==kProfDocPictSubtype)
- {
- PicHandle pict ;
- pict = GetPictDocPict( win, kOriginal ) ;
- if (!pict) return ; // nothing to draw
- }
- else
- return;
-
- paneRect = GetPictDocPaneRect( win ) ;
- pictRect = GetPictDocPictRect( win ) ; // check if ok?
-
- if (SectRect(&paneRect,&updateRect,&paneUpdateRect))
- {
- short HorzDelta, VertDelta ;
-
- HorzDelta = GetPictDocCntlValue(win,rPictDocHorzScrollID) * kScrollDelta
- + pictRect.left
- - kMargin
- - paneRect.left;
-
- VertDelta = GetPictDocCntlValue(win,rPictDocVertScrollID) * kScrollDelta
- + pictRect.top
- - kMargin
- - paneRect.top;
-
- // pictRelPaneRect = pictRect in the pane's coords
- pictRelPaneRect = pictRect ;
- OffsetRect( &pictRelPaneRect, -HorzDelta, -VertDelta ) ;
-
- // erase the pane first
- BackColor( whiteColor ) ;
- EraseRect( &paneRect ) ;
-
- // Draw the pict into the pane
- if (SectRect(&pictRelPaneRect,&paneUpdateRect,&pictUpdateRelPaneRect))
- {
- pictUpdateRect = pictUpdateRelPaneRect ;
- OffsetRect( &pictUpdateRect, HorzDelta, VertDelta ) ;
- DoDrawPictData( win, (GrafPtr)window, &pictUpdateRect, &pictUpdateRelPaneRect ) ;
- }
-
- // Draw gray crop marks (always)
- if (true)
- {
- Rect temp ;
- RgnHandle saveRgn = NewRgn() ;
-
- GetClip( saveRgn ) ;
- ClipRect( &paneRect ) ;
-
- temp = pictRelPaneRect ;
- temp.top -=1 ;
- temp.left -=1 ;
-
- RGBForeColor( &mdGray ) ;
-
- MoveTo( temp.left-8, temp.top ) ;
- LineTo( temp.left, temp.top ) ;
- LineTo( temp.left, temp.top-8 ) ;
-
- MoveTo( temp.left-8, temp.bottom ) ;
- LineTo( temp.left, temp.bottom ) ;
- LineTo( temp.left, temp.bottom+8 ) ;
-
- MoveTo( temp.right+8, temp.bottom ) ;
- LineTo( temp.right, temp.bottom ) ;
- LineTo( temp.right, temp.bottom+8 ) ;
-
- MoveTo( temp.right+8, temp.top ) ;
- LineTo( temp.right, temp.top ) ;
- LineTo( temp.right, temp.top-8 ) ;
-
- SetClip( saveRgn ) ;
- DisposeRgn( saveRgn ) ;
- }
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- ScrollPane
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void ScrollPane ( winHandle win, ControlHandle cntl, short oldCntlVal )
- {
- short newCntlVal ;
- short distHorz=0, distVert=0 ;
- ControlHandle hCtl, vCtl ;
- Rect paneRect;
- GrafPtr savedPort ;
- WindowRef window ;
-
- newCntlVal = GetControlValue( cntl ) ;
- if ( newCntlVal != oldCntlVal )
- {
- RgnHandle saveRgn = NewRgn() ;
- RgnHandle updateRgn = NewRgn() ;
-
- hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
- vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
-
- paneRect = GetPictDocPaneRect( win ) ; // determine scrolling rect
- if (cntl==vCtl)
- distVert = (oldCntlVal-newCntlVal)*kScrollDelta ;
- if (cntl==hCtl)
- distHorz = (oldCntlVal-newCntlVal)*kScrollDelta ;
- ScrollRect( &paneRect, distHorz, distVert, updateRgn) ;
-
- // instead of just calling InvalRgn here, we go through the
- // trouble of adjusting the visRgn, calling UpdatePane, and
- // and restoring the original visRgn. This way, the update
- // is handled immediately instead of waiting for the next
- // pass through the main event loop. This way, the app will
- // update correctly with CDEVs such as "Scrolling" which
- // allow live scrolling.
-
- window = GetWinWindow( win ) ;
- GetPort( &savedPort ) ;
- SetPort( (GrafPtr)window ) ;
-
- CopyRgn( ((CGrafPtr)window)->visRgn, saveRgn ) ;
- SectRgn( ((CGrafPtr)window)->visRgn, updateRgn,
- ((CGrafPtr)window)->visRgn);
-
- UpdatePane( win, (**updateRgn).rgnBBox ) ;
-
- CopyRgn( saveRgn, ((CGrafPtr)window)->visRgn ) ;
-
- SetPort( savedPort ) ;
- DisposeRgn( saveRgn ) ;
- DisposeRgn( updateRgn ) ;
- }
- }
-
-
-
- static void UpdatePict ( winHandle win, short which )
- {
- CMError cmerr ;
- PicHandle pictNew ;
- PicHandle pictOrig ;
- unsigned long totalTicks ;
- unsigned long ticks ;
- unsigned long pixels ;
- Boolean needsUpdate ;
-
- if (which==kOriginal) return ;
- if (which>=kDrwMchdPct) return ;
-
- needsUpdate = GetPictDocNeedsUpdate( win, which ) ;
- pictNew = GetPictDocPict( win, which ) ;
-
- //if ( (needsUpdate==false) && (pictNew!=nil) ) return;
- if ( needsUpdate==false ) return;
-
- if (pictNew)
- DisposeHandle( (Handle)pictNew ) ;
-
- SetUpCursors( kCSyncACursor ) ;
-
- pictOrig = GetPictDocPict(win,kOriginal) ;
-
- totalTicks = TickCount() ;
-
- switch (which)
- {
- case kMatched :
- cmerr = MatchPicHandle(
- pictOrig, &pictNew,
- GetPictDocProfile( win, kSrceProf ),
- GetPictDocProfile( win, kPrevProf ),
- &ticks,
- &pixels ) ;
- break;
- case kProofed :
- cmerr = ProofPicHandle(
- pictOrig, &pictNew,
- GetPictDocProfile( win, kSrceProf ),
- GetPictDocProfile( win, kDestProf ),
- GetPictDocProfile( win, kPrevProf ),
- &ticks,
- &pixels ) ;
- break;
- case kChecked :
- cmerr = CheckPicHandle(
- pictOrig, &pictNew,
- GetPictDocProfile( win, kSrceProf ),
- GetPictDocProfile( win, kDestProf ),
- &ticks,
- &pixels ) ;
- break;
- }
-
- totalTicks = TickCount() - totalTicks;
-
- TearDownCursors( kArrowCursor ) ;
-
- if (cmerr)
- {
- ticks = 0 ;
- WarnIfErr( cmerr ) ;
- }
-
- SetPictDocDrawTime( win, which, ticks ) ;
- SetPictDocDrawTime( win, which+kTotal, totalTicks ) ;
- SetPictDocDrawCount( win, pixels ) ;
- SetPictDocPict( win, which, pictNew ) ;
- SetPictDocNeedsUpdate( win, which, false ) ;
- }
-
-
- static void ChangeCSOnOff ( winHandle win )
- {
- Rect rect;
- short val;
-
- val = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
- SetPictDocCntlValue( win, rPictDocMatchOnOffID, !val ) ;
-
- SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ; // set the window to be the current port
- rect = GetPictDocPaneRect( win ) ;
- rect.bottom += kScrollWidth ; // inval status rect
- InvalRect( &rect ) ;
- }
-
-
- static void ChangeCSMode ( winHandle win )
- {
- Rect rect;
- short which;
-
- which = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
- if ( GetPictDocPict(win,which) == nil )
- if ( GetPictDocNeedsUpdate(win,which) == false )
- SetPictDocNeedsUpdate( win, which, true) ;
-
- SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ; // set the window to be the current port
- rect = GetPictDocPaneRect( win ) ;
- rect.bottom += kScrollWidth ; // inval status rect
- InvalRect( &rect ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- SetWinContentColor
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static Boolean SetWinContentColor ( WindowRef window, RGBColor theColor )
- {
- #if STRICT_WINDOWS
-
- return false ;
-
- #else
-
- Boolean hasAuxWinRec ;
- CTabHandle ctab ;
- short count ;
- short i ;
- AuxWinHandle awh ;
-
- hasAuxWinRec = GetAuxWin( window, &awh ) ;
- if (hasAuxWinRec)
- {
- ctab = (**awh).awCTable ;
- count = (**ctab).ctSize ;
-
- for (i=0; i<count; i++)
- if ( (**ctab).ctTable[i].value == 0 )
- (**ctab).ctTable[i].rgb = theColor ;
- }
- return hasAuxWinRec ;
-
- #endif
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetProfileFromFront
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static OSErr GetProfileFromFront ( CMProfileRef *prof )
- {
- winHandle frontWin;
- OSErr err = noErr ;
- OSType type, subtype ;
- CMProfileRef tempprof ;
-
- *prof = nil ;
-
- frontWin = GetFrontWindowWinHandle() ;
- if (!frontWin) return paramErr ;
-
- type = GetWinType( frontWin ) ;
- subtype = GetWinSubtype( frontWin ) ;
-
- if ( type==kProfileType )
- {
- if ( subtype==kFileSubType || subtype==kEmbededSubType )
- {
- tempprof = GetProfileRef(frontWin) ;
- err = ReOpenProfileRef ( prof, tempprof ) ;
- }
- else if ( subtype==kSysProfSubType )
- *prof = nil ;
- else
- err = paramErr ;
- }
- else if ( type==kProfListType )
- {
- ListHandle list ;
- Cell cell = {0,0} ;
- CMProfileLocation location;
- short dataLen;
-
- list = GetProfListList( frontWin ) ;
- if ( list && LGetSelect(true, &cell, list))
- {
-
- location.locType = cmFileBasedProfile;
- cell.h = 1;
- dataLen = sizeof(FSSpec) ;
- LGetCell( &(location.u.fileLoc.spec), &dataLen, cell, list ) ;
-
- err = CMOpenProfile( prof, &location );
- }
- else
- err = paramErr ;
- }
- else
- err = paramErr ;
-
- return err;
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetProfIDFromFront
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static OSErr GetProfIDFromFront ( CMProfileIdentifierHdl *IDHdl )
- {
- winHandle frontWin;
- OSErr err = noErr ;
- OSType type ;
-
- frontWin = GetFrontWindowWinHandle() ;
- if (!frontWin) return paramErr ;
-
- type = GetWinType( frontWin ) ;
-
- if ( type==kProfIDType )
- {
- *IDHdl = GetProfIDIDHdl( frontWin ) ;
- }
- else
- err = paramErr ;
-
- return err;
- }
-
-
-
- /*------------------------------------------------------------------------------*\
- DoChangeProfile
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void DoChangeProfile ( winHandle win, short which, CMProfileRef prof )
- {
- CMError err ;
- CMProfileRef oldProf, newProf ;
- Rect rect;
-
- oldProf = GetPictDocProfile( win, which ) ;
-
- if (oldProf == prof) return ; // this may not be wize ??
-
- // close old profile if !=nil
- err = CMCloseProfile( oldProf ) ;
-
- // reopen profile
- err = ReOpenProfileRef( &newProf, prof ) ;
- if ( err ) return ;
-
- SetPictDocProfile ( win, which, newProf ) ;
-
- // update matched pict and force update
- if (which != kDestProf)
- SetPictDocNeedsUpdate( win, kMatched, true ) ;
- SetPictDocNeedsUpdate( win, kProofed, true ) ;
- if (which != kPrevProf)
- SetPictDocNeedsUpdate( win, kChecked, true ) ;
-
- SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ; // set the window to be the current port
- rect = GetWinRect( win ) ;
- //if ( GetPictDocCntlValue(win,rPictDocMatchOnOffID) )
- // rect = header rect
- InvalRect( &rect ) ;
- }
-
- static void DoChangeProfileFromFront ( winHandle win, short which )
- {
- CMProfileRef prof;
-
- if ( GetProfileFromFront(&prof)==noErr )
- {
- DoChangeProfile( win, which, prof ) ;
- if (prof) CMCloseProfile(prof);
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoAddEmbdProf
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static OSErr DoAddEmbdProf ( winHandle win, CMProfileRef prof, unsigned long flags )
- {
- PicHandle pictOld, pictNew ;
- OSErr err = noErr ;
-
- if (prof==nil) return paramErr ;
-
- pictOld = GetPictDocPict( win, kOriginal ) ;
- err = PrependProfileToPicHandle( pictOld, &pictNew, prof, flags ) ;
- if (err) return err ;
-
- DoChangePict( win, (Handle)pictNew, kProfDocPictSubtype ) ;
- return noErr ;
- }
-
- static OSErr DoAddEmbdProfID ( winHandle win, CMProfileIdentifierHdl IDHdl )
- {
- PicHandle pictOld, pictNew ;
- OSErr err = noErr ;
-
- if (IDHdl==nil) return paramErr ;
-
- pictOld = GetPictDocPict( win, kOriginal ) ;
- HLock( (Handle)IDHdl );
- err = PrependProfileIdentToPicHandle ( pictOld, &pictNew, *IDHdl ) ;
- HUnlock( (Handle)IDHdl );
- if (err) return err ;
-
- DoChangePict( win, (Handle)pictNew, kProfDocPictSubtype ) ;
- return noErr ;
- }
-
- static void DoAddEmbdProfFromFront ( winHandle win, unsigned long flags )
- {
- CMProfileRef prof;
- CMProfileIdentifierHdl IDHdl;
-
- if ( GetProfileFromFront( &prof )==noErr )
- {
- (void) DoAddEmbdProf( win, prof, flags ) ;
- if (prof) CMCloseProfile(prof);
- }
- else if ( GetProfIDFromFront(&IDHdl)==noErr && flags==cmEmbedProfileIdentifier )
- (void) DoAddEmbdProfID( win, IDHdl ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------*\
- SaveCmndPictDoc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void SaveCmndPictDoc ( winHandle win )
- {
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- OSType subtype;
- OSErr err ;
-
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
- subtype = GetWinSubtype( win ) ;
-
- if ( !dirty ) return; // no need to save
- if ( !subtype ) return; // no need to save
-
- if ( !hasFile )
- SaveAsCmndPictDoc( win ) ;
- else
- {
- err = paramErr; // default error
- if (subtype==kProfDocPictSubtype)
- err = DoWritePICT( spec, GetPictDocPict(win,kOriginal), kCreatorType ) ;
-
- WarnIfErr( err ) ;
- if (err) return ; // if err, should do something
-
- SetWinDirty( win, false ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- SaveAsCmndPictDoc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void SaveAsCmndPictDoc ( winHandle win )
- {
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- StandardFileReply reply ;
- OSErr err ;
- WindowRef window ;
- OSType subtype;
- Str255 title ;
-
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
- window = GetWinWindow( win ) ;
- subtype = GetWinSubtype( win ) ;
-
- if ( hasFile )
- StringToString( spec.name, title ) ;
- else
- GetWTitle( window, title ) ;
-
- StandardPutFile( "\pSave PICT as:", title, &reply) ;
- if ( reply.sfGood )
- {
- err = paramErr; // default error
- spec = reply.sfFile ;
-
- if (subtype==kProfDocPictSubtype)
- err = DoWritePICT ( spec, GetPictDocPict(win, kOriginal), kCreatorType ) ;
-
- WarnIfErr( err ) ;
- if ( err ) return ; // if err, should do something
-
- SetWinFSSpec( win, &spec ) ; // win's spec = new spec
- SetWTitle( window, spec.name ) ; // win title = new title
- SetWinDirty( win, false ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- RevertCmndPictDoc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void RevertCmndPictDoc ( winHandle win )
- {
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
-
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
-
- if ( !dirty || !hasFile ) return ;
-
- // ask user if it's ok
-
- SetWinDirty( win, false ) ; // clear dirty so we don't get another dialog
- CallWinCloseProc( win ) ; // close the document
- SendODOC( &spec ) ; // reopen: send ODOC event to ourselves:
- // DoAppAdjustMenus() ; // undim app items
- }
-
-
- /*------------------------------------------------------------------------------*\
- CopyCmndPictDoc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void CopyCmndPictDoc ( winHandle win )
- {
- OSType subtype;
-
- subtype = GetWinSubtype( win ) ;
-
- if (ZeroScrap()) return ;
-
- if (subtype==kProfDocPictSubtype)
- {
- Handle hand ;
- short mode,cson;
- mode = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
- cson = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
- if (!cson) mode = kOriginal ;
- if (mode==kDrwMchdPct) mode = kOriginal;
- hand = (Handle)GetPictDocPict(win,mode) ;
- if (hand == nil)
- hand = (Handle)GetPictDocPict(win,kOriginal) ;
-
- HLock( hand ) ;
- (void) PutScrap(GetHandleSize(hand),'PICT', *hand);
- HUnlock( hand ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- PasteCmndPictDoc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void PasteCmndPictDoc ( winHandle win )
- {
- Boolean pictOnScrap ;
- long pictLength ;
- long pictOffset ;
- OSType subtype;
-
- subtype = GetWinSubtype( win ) ;
-
- pictLength = GetScrap( nil, 'PICT', &pictOffset ) ;
- pictOnScrap = ( pictLength > 0 ) ;
-
- if ( !pictOnScrap ) return ;
-
- subtype = GetWinSubtype ( win ) ;
-
- if (pictOnScrap)
- {
- PicHandle pict ;
- pict = (PicHandle) NewHandle( 0 ) ; // allocate 0-length data area
- (void) GetScrap( (Handle)pict, 'PICT', &pictOffset ) ;
- DoChangePict( win, (Handle)pict, kProfDocPictSubtype ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoChangePict
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void DoChangePict ( winHandle win, Handle hand, OSType subtype )
- {
- Rect rect, sizeRect ;
- OSErr err ;
- short h,v ;
- WindowRef window ;
- //PaletteHandle palette ;
- ListHandle profList ;
-
- {
- // ask user if it's ok
- }
-
- CallWinDisposeProc( win ) ;
- CallWinAllocProc( win ) ;
-
- if (subtype==kProfDocPictSubtype)
- {
- PicHandle pict ;
-
- pict = (PicHandle)hand;
- // set the window's pict
- SetPictDocPict( win, kOriginal, pict ) ;
-
- // set the window's rect
- rect = (**(pict)).picFrame ;
- SetPictDocPictRect( win, rect ) ;
-
- // set the window's update flags
- SetPictDocNeedsUpdate( win, kMatched, true ) ;
- SetPictDocNeedsUpdate( win, kProofed, true ) ;
- SetPictDocNeedsUpdate( win, kChecked, true ) ;
-
- // err = DoCreatePalettes( win ) ;
- // if ( err ) return ;
- }
- else
- {
- // should bail
- }
-
- SetWinSubtype( win, subtype ) ;
-
- h = rect.right - rect.left ;
- v = rect.bottom - rect.top ;
- h += kScrollWidth + kMargin + kMargin ;
- v += kScrollWidth + kMargin + kMargin + kHeaderHeight ;
- h = MAX(h, kWindowWidthMin) ;
- v = MAX(v, kWindowHeightMin+kHeaderHeight) ;
-
- window = GetWinWindow( win ) ;
- SetPort( (GrafPtr)window ) ;
- SizeWindow( window, h, v, false) ; // we'll update everything later
-
- SetRect( &sizeRect, kWindowWidthMin,
- kWindowHeightMin+kHeaderHeight,
- h+1,v+1) ;
- SetWinSizeRect( win, sizeRect ) ;
-
- // try to make list of embeded profiles
- profList = BuildProfList( win ) ;
-
- // set up drag&drop zones
- err = DoCreateDragZones( win ) ;
- if (err) return ;//err ; // we should dispose window before returning
-
- // set up scroll bars
- SetPictDocCntl( win, rPictDocHorzScrollID, GetNewControl(rPictDocHorzScrollID, window ) ) ;
- SetPictDocCntl( win, rPictDocVertScrollID, GetNewControl(rPictDocVertScrollID, window ) ) ;
- SetPictDocCntl( win, rPictDocMatchOnOffID, GetNewControl(rPictDocMatchOnOffID, window ) ) ;
- SetPictDocCntl( win, rPictDocMatchPopupID, GetNewControl(rPictDocMatchPopupID, window ) ) ;
- CallWinResizeProc( win ) ;
-
- // and if we set up the palette earlier assign it to the window
- // palette = GetPictDocPalette( win ) ;
- // if( palette != nil )
- // SetPalette ( window, palette, true ) ;
- // ActivatePalette ( window ) ;
-
- rect = GetWinRect( win ) ;
- InvalRect( &rect ) ; // force window redraw
- SetWinDirty( win, true ) ;
- DoAppAdjustMenus() ; // undim app items
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoDragPict
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static OSErr DoDragPict ( winHandle win, EventRecord *e, Rect hiliteRect )
- {
- short result;
- RgnHandle dragRegion;
- Point theLoc = {0,0};
- DragReference theDrag;
- AEDesc dropLocation;
- DragAttributes attributes;
- short mouseDownModifiers, mouseUpModifiers, copyText;
- DragSendDataUPP myDragSendDataUPP ;
- OSType subtype;
-
- if ( win == nil )
- return paramErr ;
-
- subtype = GetWinSubtype( win ) ;
- if ( subtype == nil )
- return paramErr ;
-
- dragRegion = NewRgn() ;
- RectRgn(dragRegion,&hiliteRect) ;
- LocalToGlobal(&theLoc) ;
- OffsetRgn( dragRegion, theLoc.h, theLoc.v ) ;
-
- // Wait for the mouse to move to the mouse button to be released.
- // If the mouse button was released before the mouse moves, return.
- if (! WaitMouseMoved(e->where))
- return noErr ; // should return something to indicate no drag occured
-
- // create a new reference for a track to pass to track drag
- NewDrag(&theDrag) ;
-
- // We promise 'PICT'. If a receiver requests either, the Drag Manager
- // will call our MyDragSendDataProc to provide the data at drop time. The MyDragSendDataProc
- // is specified by calling SetDragSendProc.
- AddDragItemFlavor( theDrag, 1, 'PICT', nil, 0L, 0L) ;
- myDragSendDataUPP = NewDragSendDataProc( MyDragSendDataProc ) ;
- SetDragSendProc( theDrag, myDragSendDataUPP, (void *)win ) ;
-
- // Set the item's bounding rectangle in global coordinates.
- SetDragItemBounds(theDrag, 1, &(**dragRegion).rgnBBox) ;
-
- // Prepare the drag region.
- (void) OutlineRegion( dragRegion ) ;
-
- // Drag the stuff. TrackDrag will return userCanceledErr if the drop zoomed-back for any reason.
- result = TrackDrag(theDrag, e, dragRegion) ;
-
- // get rid of the UPP
- DisposeRoutineDescriptor( myDragSendDataUPP ) ;
-
- if (result != noErr && result != userCanceledErr)
- return result ;
-
- // Check to see if the drop occurred in the Finder's Trash. If the drop occurred
- // in the Finder's Trash and a copy operation wasn't specified, delete the
- // source selection. Note that we can continute to get the attributes, drop location
- // modifiers, etc. of the drag until we dispose of it using DisposeDrag.
- GetDragAttributes(theDrag, &attributes) ;
- if (!(attributes & kDragInsideSenderApplication))
- {
- GetDropLocation(theDrag, &dropLocation) ;
- GetDragModifiers(theDrag, 0L, &mouseDownModifiers, &mouseUpModifiers) ;
- copyText = (mouseDownModifiers | mouseUpModifiers) & optionKey;
-
- if ( !copyText && DropLocationIsFinderTrash(theDrag) )
- {
- }
- AEDisposeDesc(&dropLocation) ;
- }
-
- // Dispose of the drag.
- DisposeDrag(theDrag) ;
- DisposeRgn(dragRegion) ;
-
- return noErr ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- MyDragSendDataProc
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static pascal OSErr MyDragSendDataProc ( FlavorType theDragFlavor, void *refCon,
- ItemReference theItem, DragReference theDrag)
-
- {
- winHandle win=nil ;
- Handle hand=nil ;
- OSErr err=noErr ;
- OSType subtype;
-
- win = (winHandle) refCon ;
- subtype = GetWinSubtype( win ) ;
-
- // so what do they want??
- if ( theDragFlavor == 'PICT' && subtype != nil)
- {
- short mode,cson;
- mode = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
- cson = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
- if (!cson) mode = kOriginal ;
- if (mode==kDrwMchdPct) mode = kOriginal;
- hand = (Handle)GetPictDocPict(win,mode) ;
- if (hand == nil)
- hand = (Handle)GetPictDocPict(win,kOriginal) ;
- HLock(hand) ;
- SetDragItemFlavorData( theDrag, theItem,
- 'PICT', (Ptr) *hand,
- GetHandleSize(hand), 0L ) ;
- }
- else
- return badDragFlavorErr ;
- return noErr ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- MyDragZoneRecvCallback
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static pascal OSErr MyDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow,
- Point theLocation, Handle dataHdl )
- {
- winHandle win=nil ;
- Handle pict=nil ;
- OSErr err=noErr ;
- FlavorType theDragFlavor ;
- OSType subtype;
-
- win = GetWindowWinHandle( theWindow ) ;
- theDragFlavor = (**theZone).flavor ;
-
- if ( theDragFlavor=='PICT')
- {
- pict = dataHdl ;
- err = HandToHand( &pict ) ;
- subtype = kProfDocPictSubtype ;
- goto bail ;
- }
-
- if( theDragFlavor==flavorTypeHFS ) // do this on receipt of an HFS flavor (a file from the finder)
- {
- HFSFlavor theHFSFlavor ;
- HLock( dataHdl ) ;
- theHFSFlavor = *((HFSFlavor *)*dataHdl) ;
- if ( theHFSFlavor.fileType == 'PICT' ) // get the picture from the file
- {
- err = DoReadPICT( theHFSFlavor.fileSpec, (PicHandle*)&pict ) ;
- subtype = kProfDocPictSubtype ;
- goto bail ;
- }
- }
-
- bail:
-
- if ( win && pict && !err )
- DoChangePict( win, pict, subtype ) ;
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- MyProfDragZoneRecvCallback
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static pascal OSErr MyProfDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow,
- Point theLocation, Handle dataHdl )
- {
- winHandle win=nil ;
- OSErr err=noErr ;
- FSSpec spec ;
- CMProfileRef prof ;
- short which ;
-
- win = GetWindowWinHandle( theWindow ) ;
- spec = ((HFSFlavor *)*dataHdl)->fileSpec ;
-
- err = OpenProfileFSSpec( spec, &prof ) ;
- which = (short)((**theZone).zoneRefCon) ;
-
- if ( win && prof && !err )
- {
- switch (which)
- {
- case kSrceProf :
- case kDestProf :
- case kPrevProf :
- DoChangeProfile( win, which, prof ) ;
- break ;
- case kEmbedProfs :
- err = DoAddEmbdProf( win, prof, cmEmbedWholeProfile ) ;
- break ;
-
- }
- }
- return err ;
- }
-